package edu.hawaii.duedates.book;

import static org.junit.Assert.assertEquals;
import java.util.Calendar;
import org.junit.Test;

/**
 * This will test the Book class.
 * 
 * @author Ronn Reeves and Robin E. Raqueno
 */
public class TestBook {
  Calendar today = Calendar.getInstance();

  /**
   * Test creating a book.
   */
  @Test
  public void testCreateBook() {
    String title = "Title";
    String library = "Test library";
    Book book = new Book(title, today, library);
    book.setDueDate(today);
    book.setLibrary(library);
    book.setTitle(title);

    assertEquals("toString() test failed.", book.toString(), book.getTitle());
    assertEquals("getTitle() test failed.", title, book.getTitle());
    assertEquals("getDueDate() test failed.", today, book.getDueDate());
    assertEquals("getLibrary() test failed.", library, book.getLibrary());
  }

  /**
   * Test the formatString and formatDate.
   */
  @Test
  public void testTitleFormat() {
    String longTitle = "TitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
        + "TitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitle";
    String library = "Kaimuki Library";
    String failMessage = "getTitle() test format failed.";

    String bookTitle1 = longTitle;
    Book book1 = new Book(bookTitle1, today, library);

    assertEquals(failMessage, book1.toString(), book1.getTitle());
    assertEquals("getDueDate() test format failed.", book1.getDueDate(), book1.getDueDate());

    String frontTrim = "TRIM_FROM_FRONT  ";
    String endTrim1 = "/TRIM_FROM_END";
    String endTrim2 = " Location:_TRIM_FROM_END";

    String bookTitle2 = frontTrim + longTitle + endTrim1 + endTrim2;
    Book book2 = new Book(bookTitle2, today, library);

    assertEquals(failMessage, book2.toString(), book2.getTitle());

    String bookTitle3 = "Location:" + longTitle + '/' + "  " + endTrim1;
    Book book3 = new Book(bookTitle3, today, library);

    assertEquals(failMessage, book3.toString(), book3.getTitle());

    String bookTitle4 = frontTrim + " " + longTitle + endTrim2;
    Book book4 = new Book(bookTitle4, today, library);

    assertEquals(failMessage, book4.toString(), book4.getTitle());

    frontTrim = "Location:TRIM_FROM_FRONT  ";
    String bookTitle5 = frontTrim + longTitle;
    Book book5 = new Book(bookTitle5, today, library);
    System.out.println(book5.getTitle());

    assertEquals(failMessage, book5.toString(), book5.getTitle());
  }
}